<template>
  <view class="wallet">
    <view class="container">
      <!-- <view class="money">
        <view class="num">¥{{money.all_money.toFixed(2)}}</view>
        <view class="backMoney"><AtButton size="small"  type='primary' @click="getMoneyBack">立即返还</AtButton></view>
      </view> -->
      <view class="content">
          <scroll-view
            style="height: 100%;"
            :refresherEnabled="true"
            :scroll-y="true"
            :lowerThreshold="100"
            :refresherTriggered="isFresh"
            @refresherRefresh="refresherRefresh"
            @scrolltolower="loadMore"
          >
            <view v-if="OrderRecord.length" class="orderItem" v-for="item in OrderRecord" :key="item.o_order_code">
              <view class="topStatus">
                <view class="orderCode">眼镜编码: <text style="position: relative; top: -5rpx;">{{item.go_g_code}}</text></view>
                <view class="status alreadyComplate">
                  已取镜
                </view>
              </view>
              <view class="middleContent">
                <view class="middleImg">
                  <view class="itemBox">
                    <view class="order-item">眼镜名称: {{ item.t_type_name }}</view>
                    <view class="order-item">眼镜数量: 1副</view>
                    <!-- <view class="order-item" v-if="item.go_status == 1">归还状态:   <AtTag >{{ item.return_status }}</AtTag></view> -->
                    <view class="order-item">订单编码: {{ item.o_order_code }}</view>
                    <view class="order-item">下单时间: {{ item.go_order_date }}</view>
                    <view class="order-item">借出时间: {{ item.go_output_time }}</view>
                    <!-- <view class="order-item" v-if="item.go_status == 1">归还时间: {{ item.go_input_time }}</view> -->
                  </view>
                </view>
              </view>
            </view>
            <view class="no_list" v-if="noDataTrue"></view>
            <AtLoadMore v-if="dataStatus" :status="loadMoreStatus"/>
          </scroll-view>


      </view>
    </view>
  </view>
</template>

<script setup>
import './index.scss'
import { AtLoadMore, AtTag } from 'taro-ui-vue3'
import {query_balance, do_refund, return_order_glasses_list} from '../../http/api'
import {ref, reactive} from 'vue'
import Taro, {useDidShow} from '@tarojs/taro'

const imgUrl = require('../index/imgs/e1.png')
const isFresh = ref(false)
const loadMoreStatus = ref('loading')
const dataStatus = ref(false)
const totalNum = ref(0)
const money = reactive({
  all_money: 0,
  t_money: 0
})
//  分页相关
const pageInfo = reactive({
  page: 1,
  page_size: 5
})
const noDataTrue = ref(false)


function getMoney () {
  query_balance().then(res => {
    money.all_money = res.data.all_money
    money.t_money = res.data.t_money
  })
}
const OrderRecord = ref([])
function returnOrderRecord () {
  loadMoreStatus.value = 'loading'
  return_order_glasses_list(pageInfo).then(res => {
    if (res.code == '1000') {
      OrderRecord.value = [...OrderRecord.value, ...res.data.data_list];
      totalNum.value = res.data.total;
      noDataTrue.value = !OrderRecord.value.length
      loadMoreStatus.value = 'nomore'
      isFresh.value = false
      dataStatus.value = false
    }
  })
}
// 下拉刷新
const refresherRefresh = () => {
  isFresh.value = true;
  pageInfo.page = 1;
  OrderRecord.value = [];
  returnOrderRecord()
}
// 加载更多
const loadMore = () => {
  if (loadMoreStatus.value == 'loading') return
  dataStatus.value = true
  pageInfo.page += 1;
  if (totalNum.value == OrderRecord.value.length) {
      dataStatus.value = true
      loadMoreStatus.value = 'noMore'
  } else {
    returnOrderRecord()
  }
}

function gotoPayHtml(code) {
  Taro.navigateTo({
    url: `/pages/orderDetail/index?o_order_code=${code}&o_is_refund=-1`
  })
}

useDidShow(() => {
  getMoney()
  pageInfo.page = 1;
  OrderRecord.value = [];
  returnOrderRecord()
})
Taro.showShareMenu({
  withShareTicket: true,
  menus: ['shareAppMessage', 'shareTimeline']
})
</script>
